package richrail.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import richrail.RichRailApp;
import richrail.tools.CommandParser;

public class MainPanel extends JFrame implements ActionListener {

	private static final long serialVersionUID = 1L;

	RichRailApp app;
	JTextField commandTextField;

	public MainPanel(RichRailApp app) {
		this.app = app;
		initGUI();
	}

	private void initGUI(){
		this.setTitle("RichRail - v1.0");
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setBounds(0, 0, 400, 400);
		this.setPreferredSize(new java.awt.Dimension(400, 400));
		this.setSize(800, 600);
		this.setBackground(new java.awt.Color(0,0,0));
		//this.setBackground(java.awt.Color.LIGHT_GRAY);
		this.setLayout(null);
		this.setForeground(new java.awt.Color(255,255,255));
		{
			ImageDrawGaragePanel imagePanel = new ImageDrawGaragePanel(app.getGarage());
			this.add(imagePanel);
			imagePanel.setBounds(0, 0, 800, 200);
			imagePanel.setBackground(java.awt.Color.WHITE);
		}
		{
			TextualGaragePanel garagePanel = new TextualGaragePanel(app.getGarage());
			this.add(garagePanel);
			garagePanel.setBounds(1, 200, 350, 200);
			garagePanel.setBackground(new java.awt.Color(200,200,200));
		}
		{
			JLabel outputText = new JLabel();
			this.add(outputText);
			outputText.setText("output");
			outputText.setBounds(385, 175, 50, 100);
		}
		{
			TextualOutputPanel garagePanel = new TextualOutputPanel(app.getGarage());
			this.add(garagePanel);
			garagePanel.setBounds(433, 200, 350, 200);
			garagePanel.setBackground(new java.awt.Color(200,200,200));
		}
		{
			JLabel commandText = new JLabel();
			this.add(commandText);
			commandText.setText("command");
			commandText.setBounds(10, 370, 100, 100);
		}
		{
			commandTextField = new JTextField();
			this.add(commandTextField);
			commandTextField.setBounds(85, 408, 180, 25);
		}
		{
			JButton executeButton = new JButton();
			this.add(executeButton);
			executeButton.setText("execute");
			executeButton.setBounds(270, 408, 80, 25);
			executeButton.addActionListener(this);
		}
	}

	public void actionPerformed(ActionEvent arg0) {
		CommandParser.getInstance().parseCommand(commandTextField.getText());
	}
}
